var func = {};

func.px = function(css) {
    return parseInt(css);
};

func.offset = function(selector) {
    var f = $(selector).offset();
    console.log(f);
}

func.checkIntersecion = function (s, b) {
    var js = $(s), jb = $(b), jst = $('.user_profile_stack');
    var small = {}, big = {}, stack = {};

    // Get width
    small.width = js.width();
    small.width_2 = Math.floor(small.width/2);
    big.width = jb.width();
    stack.width = jst.width();

    small.height = js.height();
    small.height_2 = Math.floor(small.height/2);
    big.height = jb.height();
    stack.height = jst.height();

    small.top = js.offset().top;
    big.top = jb.offset().top;
    stack.top = jst.offset().top;

    small.left = js.offset().left;
    big.left = jb.offset().left;
    stack.left = jst.offset().left;

    // Check in
    if ((big.left<=small.left) && (big.left+big.width>=small.left+small.width) &&
        (small.top>=big.top) && (small.top+small.height<=big.top+big.height)) {
        //console.log('IN BOX');
        return true;
    }

    // Case 1 TOP
    if (((small.top+small.height-big.top>small.height_2) && (small.top+small.height>big.top) && (small.top<big.top)) ||
        (((small.top<big.top+big.height) && (small.top+small.height>big.top+big.height)) &&
            ((small.top+small.height)-(big.top+big.height)<small.height_2)) ||
        ((big.top<small.top) && (big.top+big.height>small.top+small.height))
        ) {

        if (((small.left+small.width_2<big.left+big.width) && (small.left<big.left+big.width) && (small.left+small.width>big.left+big.width)) ||
        ((small.left+small.width_2>big.left) && (small.left<big.left)) ||
            ((big.left<small.left)&& (small.left+small.width<big.left+big.width))
         )
        {
            return true;
        }
    }

    return false;
}

func.swap = function (id1, id2)
{
    var element1 = document.getElementById(id1);
    var element2 = document.getElementById(id2);
    var clonedElement1 = element1.cloneNode(true);
    var clonedElement2 = element2.cloneNode(true);
    element2.parentNode.replaceChild(clonedElement1, element2);
    element1.parentNode.replaceChild(clonedElement2, element1);

    return clonedElement1;
}
